package com.codeforces.gym.g100184;

import java.util.Scanner;

public class G {

	static Scanner scanner = new Scanner(System.in);
	static int N, maxv, sm, bi;

	public static void main(String[] args) {
		N = scanner.nextInt();
		maxv = -1;
		for (int a=N-1;a>=0;--a) {
			for (int b=a;b>=0;--b) {
				int val = a*b;
				if (palin(val)) {
					if (val > maxv) {
						maxv = val;
						sm = b;
						bi = a;
					}
					else if (val == maxv) {
						if (b < sm) {
							b = sm;
							bi = a;
						}
					}
				}
			}
		}
		System.out.println(sm + " " + bi);
	}

	private static boolean palin(int val) {
		String s = "" + val;
		int fr = 0;
		int to = s.length() - 1;
		while (fr < to) {
			if (s.charAt(fr) != s.charAt(to)) {
				return false;
			}
			fr++;
			to--;
		}
		return true;
	}

}
